$(
	function(){
		console.log("已经找到js");
		showMenu();
	}
)

// 查询菜单
function showMenu() {
    let url = $("#addr").val() + "/menu/Menu";

    // ajax请求
    $.ajax({
        type: "POST",
        url: url, // 请求的URL
        data: JSON.stringify({}), // 请求的数据
        dataType: "json", // 返回的数据类型，json, html, xml, jquery.parseJson()
        contentType: "application/json;charset=utf-8", // 请求的数据格式，字符集
        async: true, // 可以不写， 是否异步请求
        success: function (data, textStatus, jqXHR) {//success是一个回调函数，用来处理当AJAX请求成功完成时的操作
            console.log("返回数据::: " + data.code);
            console.log("返回数据::: " + data.msg);
            console.log("返回数据-data::: " + data.data);

            let arrData = data.data;

            for (let i = 0; i < arrData.length; i++) {
                let sBuf = "";
                let menu = arrData[i];
                sBuf = sBuf + '<li class="nav-item">';
                sBuf = sBuf + '<a class="nav-link collapsed" data-bs-target="#id' + menu.id + '" data-bs-toggle="collapse"';
                sBuf = sBuf + 'href="' + menu.path + '">'; 
                sBuf = sBuf + '<i class="bi bi-menu-button-wide"></i><span>' + menu.name + '</span><i class="bi bi-chevron-down ms-auto"></i>';
                sBuf = sBuf + "</a>";

                // 判断是否有页面
                if (menu.children.length > 0) {
                    sBuf = sBuf + '<ul id="id' + menu.id + '" class="nav-content collapse " data-bs-parent="#sidebar-nav">';
                    for (let iSub = 0; iSub < menu.children.length; iSub++) {
                        sBuf = sBuf + "<li>";
                        sBuf = sBuf + '<a href="' + $("#addr").val() + '/' + menu.children[iSub].path + '">';
                        sBuf = sBuf + '<i class="bi person-lines-fill"></i><span>' + menu.children[iSub].name + "</span>";
                        sBuf = sBuf + "</a>";
                        sBuf = sBuf + "</li>";
                    }
                    sBuf = sBuf + "</ul>";
                }

                sBuf = sBuf + "</li>";
                $("#sidebar-nav").append(sBuf);
            }
        },
    });
}
